angular.module('fs.waf').controller('poi.demo.fsDateRangeController', [
  '$scope',
  '$q',
  function($scope, $q) {
    var ctrl = this;

    var curDate = new Date();
    var initDate = new Date(curDate.getTime() - 3 * 24 * 60 * 60 * 1000);
    var preDate = new Date(curDate.getTime() - 5 * 24 * 60 * 60 * 1000);
    var nextDate = new Date(curDate.getTime() + 3 * 24 * 60 * 60 * 1000);

    ctrl.ngModel = {
      dateRangeValue: {
        from: new Date(),
        to: new Date()
      }
    };

    ctrl.layoutConfig = {
      demo: {
        name: 'demo',
        gridGroups: [
          {
            grids: ['edit', 'readonly', 'view']
          },
          {
            grids: ['vm_options', 'vm_string']
          }
        ],
        gridConfigs: {
          valueText: {
            name: 'text',
            label: 'value',
            size: 2,
            type: 'text',
            model: 'textValue',
            appScope: $scope,
            showStyle: 'edit',
            tooltip: 'value'
          },
          displayText: {
            name: 'text',
            label: 'display',
            size: 2,
            type: 'text',
            model: 'displayText',
            appScope: $scope,
            showStyle: 'edit',
            tooltip: 'display',
            uppercase: false
          },
          changeData: {
            name: 'button',
            label: 'changeData',
            size: 2,
            type: 'button',
            appScope: $scope,
            text: 'Add Data',
            tooltip: 'button tooltip',
            options: {
              icon: 'setup',
              showIcon: false,
              callback: {
                click: 'vm.changeData'
              }
              // hotKey: 'alt+1'
            }
          },
          edit: {
            name: 'dateRange',
            label: 'edit',
            size: 4,
            showStyle: 'edit', 

            type: 'datetime-range', 
            model: 'dateRangeValue',
            appScope: $scope,

            tooltip: 'dateRange tooltip',
            format: 'timestamp', 
            options: {
              ccy: 'USD' 
            }
          },
          readonly: {
            name: 'dateRange',
            label: 'readonly',
            size: 4,
            showStyle: 'readonly', 

            type: 'datetime-range', 
            model: 'dateRangeValue',
            appScope: $scope,

            tooltip: 'dateRange tooltip',
            format: 'timestamp', 
            options: {
              ccy: 'USD' 
            }
          },
          view: {
            name: 'dateRange',
            label: 'view',
            size: 4,
            showStyle: 'view', 

            type: 'datetime-range', 
            model: 'dateRangeValue',
            appScope: $scope,

            tooltip: 'dateRange tooltip',
            format: 'timestamp', 
            options: {
              ccy: 'USD' 
            }
          },
          vm_options: {
            name: 'dateRange',
            label: 'vm_options',
            size: 4,
            showStyle: 'edit', 

            type: 'datetime-range', 
            model: 'dateRangeValue1',
            appScope: $scope,

            tooltip: 'dateRange tooltip',
            format: 'timestamp', 
            options:'vm.testOptions'
          },
          vm_string: {
            name: 'dateRange',
            label: 'vm_string',
            size: 4,
            showStyle: 'edit', 

            type: 'datetime-range', 
            model: 'dateRangeValue2',
            appScope: $scope,

            tooltip: 'dateRange tooltip',
            format: 'timestamp', 
            options: {
              mode: 'vm.options.mode',
              startingDay: 'vm.options.mode',
              dateDisabled: 'vm.isDisabled',
              maxDate: 'vm.options.maxDate',
              minDate: 'vm.options.minDate',
              initDate: 'vm.options.initDate',
              ccy: 'vm.options.ccy'
            }
          }
        }
      }
    };

    ctrl.testOptions = {
      mode: 'vm.options.mode',
      startingDay: 'vm.options.mode',
      // dateDisabled: 'vm.isDisabled',
      maxDate: 'vm.options.maxDate',
      minDate: 'vm.options.minDate',
      initDate: 'vm.options.initDate',
      ccy: 'vm.options.ccy'
    };

    ctrl.options = {
      ccy: 'USD',
      mode: 'day',
      // maxMode: 'year',
      // minMode: 'day',
      startingDay: 3,
      // dateDisabled: false,
      maxDate: nextDate,
      minDate: preDate,
      initDate: initDate
      // holidaySelectable: true
    };

    ctrl.normalData = [
      {
        disabled: false,
        display: 'Jack',
        value: 123
      },
      {
        disabled: false,
        display: 'Lee',
        value: 456
      }
    ];

    ctrl.componentStyle = [
      {
        value: 'edit',
        display: 'edit'
      },
      {
        value: 'readonly',
        display: 'readonly'
      },
      {
        value: 'view',
        display: 'view'
      }
    ];

    ctrl.changeData = function() {
      if (ctrl.ngModel.textValue && ctrl.ngModel.displayText) {
        ctrl.normalData.push({
          value: ctrl.ngModel.textValue,
          display: ctrl.ngModel.displayText
        });
      }
    };

    ctrl.clickFun = function() {
      console.log(ctrl.ngModel.linkValue);
    };

    ctrl.isDisabled = function(obj) {
      return true;
    };
  }
]);
